/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package br.great.config;

import java.io.*;
import java.util.ArrayList;


//Esta classe possui métodos que criam, escrevem e deletam os arquivos
//FacebookName.txt, FacebookBluetooth.txt e FacebookBirthday.txt,
//onde ficam guardados os dados do usuário e de seus amigos.
public class FacebookData {

    public static PrintStream writeFacebookName(String name) throws FileNotFoundException{
   
        File file = new File(name + "Name.txt");

        if (! file.exists()) {
         return new PrintStream (file);
        }
        else{
            return null;
        }
    }

    public static PrintStream writeFacebookBluetooth(String name) throws FileNotFoundException{

        File file = new File(name + "Bluetooth.txt");

        if (! file.exists()) {
         return new PrintStream (file);
        }
        else{
            return null;
        }
    }

    public static PrintStream writeFacebookBirthday(String name) throws FileNotFoundException{

        File file = new File(name + "Birthday.txt");

        if (! file.exists()) {
         return new PrintStream (file);
        }
        else{
            return null;
        }
    }


public static ArrayList<String> readFacebookName(String nome) throws FileNotFoundException, IOException{
 
    FileInputStream fstream = new FileInputStream(nome + "Name.txt");
    
    DataInputStream in = new DataInputStream(fstream);
        BufferedReader br = new BufferedReader(new InputStreamReader(in));
    String strLine;
    
    ArrayList<String> name = new ArrayList<String>();
    
    while ((strLine = br.readLine()) != null)   {
      // Print the content on the console
      name.add(strLine);
    }
    //Close the input stream
    in.close();
    fstream.close();
    return name;

}

public static ArrayList<String> readFacebookBluetooth(String name) throws FileNotFoundException, IOException{

    FileInputStream fstream = new FileInputStream(name + "Bluetooth.txt");

    DataInputStream in = new DataInputStream(fstream);
        BufferedReader br = new BufferedReader(new InputStreamReader(in));
    String strLine;

    ArrayList<String> bluetooth = new ArrayList<String>();

    while ((strLine = br.readLine()) != null)   {
      // Print the content on the console
      bluetooth.add(strLine);
    }
    //Close the input stream
    in.close();
    fstream.close();
    return bluetooth;

}

public static ArrayList<String> readFacebookBirthday(String name) throws FileNotFoundException, IOException{

    FileInputStream fstream = new FileInputStream(name + "Birthday.txt");

    DataInputStream in = new DataInputStream(fstream);
        BufferedReader br = new BufferedReader(new InputStreamReader(in));
    String strLine;
    ArrayList<String> birth = new ArrayList<String>();


    while ((strLine = br.readLine()) != null)   {

        
            birth.add(strLine);
        
    }
    //Close the input stream
    in.close();

    fstream.close();

    return birth;

}

public static boolean deleteFacebookName(String name)
{
String fileName = name + "Name.txt";
    // A File object to represent the filename
    File f = new File(fileName);

    // Make sure the file or directory exists and isn't write protected
    if (!f.exists())
      throw new IllegalArgumentException(
          "Delete: no such file or directory: " + fileName);

    if (!f.canWrite())
      throw new IllegalArgumentException("Delete: write protected: "
          + fileName);

    // If it is a directory, make sure it is empty
    if (f.isDirectory()) {
      String[] files = f.list();
      if (files.length > 0)
        throw new IllegalArgumentException(
            "Delete: directory not empty: " + fileName);
    }

    // Attempt to delete it
    boolean success = f.delete();
    return success;
    }

public static boolean deleteFacebookBluetooth(String name)
{
String fileName = name + "Bluetooth.txt";
    // A File object to represent the filename
    File f = new File(fileName);

    // Make sure the file or directory exists and isn't write protected
    if (!f.exists())
      throw new IllegalArgumentException(
          "Delete: no such file or directory: " + fileName);

    if (!f.canWrite())
      throw new IllegalArgumentException("Delete: write protected: "
          + fileName);

    // If it is a directory, make sure it is empty
    if (f.isDirectory()) {
      String[] files = f.list();
      if (files.length > 0)
        throw new IllegalArgumentException(
            "Delete: directory not empty: " + fileName);
    }

    // Attempt to delete it
    boolean success = f.delete();

    return success;
    }

public static boolean deleteFacebookBirthday(String name)
{
String fileName = name + "Birthday.txt";
    // A File object to represent the filename
    File f = new File(fileName);

    // Make sure the file or directory exists and isn't write protected
    if (!f.exists())
      throw new IllegalArgumentException(
          "Delete: no such file or directory: " + fileName);

    if (!f.canWrite())
      throw new IllegalArgumentException("Delete: write protected: "
          + fileName);

    // If it is a directory, make sure it is empty
    if (f.isDirectory()) {
      String[] files = f.list();
      if (files.length > 0)
        throw new IllegalArgumentException(
            "Delete: directory not empty: " + fileName);
    }

    // Attempt to delete it
    boolean success = f.delete();

    return success;
    }

    public static boolean deleteFacebookToken(String name)
{
String fileName = name + "Token.txt";
    // A File object to represent the filename
    File f = new File(fileName);

    // Make sure the file or directory exists and isn't write protected
    if (!f.exists())
      throw new IllegalArgumentException(
          "Delete: no such file or directory: " + fileName);

    if (!f.canWrite())
      throw new IllegalArgumentException("Delete: write protected: "
          + fileName);

    // If it is a directory, make sure it is empty
    if (f.isDirectory()) {
      String[] files = f.list();
      if (files.length > 0)
        throw new IllegalArgumentException(
            "Delete: directory not empty: " + fileName);
    }

    // Attempt to delete it
    boolean success = f.delete();
    return success;
    }

}

